package com.glsc.ngateway.platform.repo.softLegal;

import com.glsc.ngateway.platform.domain.softLegal.SoftLegalSerialNumber;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SoftLegalSerialNumberRepository extends JpaRepository<SoftLegalSerialNumber, Integer>, JpaSpecificationExecutor<SoftLegalSerialNumber> {

    @Query(value = "select m from SoftLegalSerialNumber m where m.isDelete=0 " +
            "and (:#{#paramSearchDto.softwareName} is null OR m.softwareName LIKE CONCAT('%', :#{#paramSearchDto.softwareName},'%') ) " +
            "and (:#{#paramSearchDto.authorizationAndLicense} is null OR m.authorizationAndLicense LIKE CONCAT('%', :#{#paramSearchDto.authorizationAndLicense},'%') ) " +
            "and (:#{#paramSearchDto.softwareSerialNumber} is null OR m.softwareSerialNumber LIKE CONCAT('%', :#{#paramSearchDto.softwareSerialNumber},'%') ) " +
            "and (:#{#paramSearchDto.insertTime} is null OR m.insertTime= :#{#paramSearchDto.insertTime}) " +
            "and (:#{#paramSearchDto.updateTime} is null OR m.updateTime= :#{#paramSearchDto.updateTime})")
    Page<SoftLegalSerialNumber> searchByParam(Pageable pageable, SoftLegalSerialNumber paramSearchDto);

    List<SoftLegalSerialNumber> findAllBySoftwareNameAndIsDelete(String softwareName, Integer noDelete);


//    @Transactional
//    @Modifying
//    @Query(value = "update t_cmdb_cpu_detail set is_delete = :deleted where cpu_detail_code in :codes ", nativeQuery = true)
//    void updateIsDeleteByCodes(Integer deleted, List<String> codes);
//
//    @Transactional
//    @Modifying
//    @Query(value = "update t_cmdb_cpu_detail set is_delete = :deleted where location_id = :deviceDetailId and life_status = 1", nativeQuery = true)
//    void updateIsDeleteByDeviceDetailId(Integer deleted, Integer deviceDetailId);
//
//    List<SoftLegalSerialNumber> findAllBySnAndIsDelete(String sn, Integer noDelete);
//
//    SoftLegalSerialNumber findByCpuDetailId(Integer cpuDetailId);
//
//    List<SoftLegalSerialNumber> findAllByCpuDetailCodeIn(List<String> collect);
//
//    List<SoftLegalSerialNumber> findAllByDeviceCodeAndIsDelete(String deviceCode, Integer noDeleted);

}
